function sksqOption(data, legendName = "") {
  if (data.length < 1) {
    return {};
  }
  let xData = [];
  let skswData = [];
  let ssxslData = [];
  let sythkrData = [];

  data.forEach((element) => {
    xData.push(element.label);
    skswData.push(element.sksw * 100);
    ssxslData.push(element.ssxsl * 100);
    sythkrData.push(element.sythkr * 100);
  });

  const option = {
    legend: {
      data: legendName,
      textStyle: {
        color: "#fff",
      },
    },
    tooltip: {
      trigger: "axis",
    },
    grid: {
      left: "15%",
      right: "15%",
      bottom: "15%",
    },
    xAxis: {
      type: "category",
      axisLabel: {
        formatter: function (params) {
          var str = ""; // 最终拼接成的字符串
          var paramsLen = params.length; // 获取每项文字的个数
          var len = 4; // 每行能显示的字的个数（根据实际情况自己设置）
          var rowNumber = Math.ceil(paramsLen / len); // 换行的话，需要显示几行，向上取整
          if (paramsLen > len) {
            //大于设定的len就换行，不大于就不变化
            for (var i = 0; i < rowNumber; i++) {
              var temp = ""; // 表示每一次截取的字符串
              var start = i * len; // 开始截取的位置
              var end = start + len; // 结束截取的位置
              if (i == rowNumber - 1) {
                // 最后一次不换行
                temp = params.substring(start, paramsLen);
              } else {
                // 每一次拼接字符串并换行
                temp = params.substring(start, end) + "\n";
              }
              str += temp; // 最终拼成的字符串
            }
          } else {
            // 给新的字符串赋值
            str = params;
          }
          return str; //返回字符串
        },
        interval: 0,
        color: "#fff",
      },
      data: xData,
    },
    yAxis: [
      {
        name: "水位 : M",
        nameTextStyle: {
          color: "rgba(255,255,255,0.8)",
        },
        splitLine: {
          lineStyle: {
            type: "dashed",
          },
        },
        axisLabel: {
          color: "#fff",
        },
        type: "value",
      },
      {
        name: "水量 : 万m³",
        nameTextStyle: {
          color: "rgba(255,255,255,0.8)",
        },
        splitLine: {
          show: false,
        },
        axisLabel: {
          color: "#fff",
        },
        type: "value",
      },
    ],
    series: [
      {
        name: "水库水位",
        data: skswData,
        type: "bar",
        color: "#FFF2B0",
        symbolSize: 8,
        barWidth: 14,
      },
      {
        yAxisIndex: 1,
        name: "实时蓄水量",
        data: ssxslData,
        type: "bar",
        color: "#78C1FF",
        symbolSize: 8,
        barWidth: 14,
      },
      {
        yAxisIndex: 1,
        name: "剩余调洪库容",
        data: sythkrData,
        type: "bar",
        color: "#8DFFC4",
        symbolSize: 8,
        barWidth: 14,
      },
    ],
  };
  return option;
}

export default sksqOption;
